import com.android.build.api.dsl.CommonExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

class AndroidLibraryConventionPlugin: Plugin<Project> {
    override fun apply(target: Project) {
        with(target){

            //id("com.android.library")
            //    id ("org.jetbrains.kotlin.android")
            //    id ("kotlin-kapt")
            //    id ("com.google.dagger.hilt.android")
            with(pluginManager){
                apply("com.android.library")
                apply("org.jetbrains.kotlin.android")
                apply("kotlin-kapt")
//                apply("com.google.dagger.hilt.android")
            }
            extensions.configure<com.android.build.gradle.LibraryExtension> {
                configureKotlinAndroid(this)
                defaultConfig.targetSdk = 34
                defaultConfig{

                }
            }
        }
    }

    private fun Project.configureKotlinAndroid(commonExtension: CommonExtension<*, *, *, *>,) {
        commonExtension.apply {
            compileSdk = 34
            defaultConfig {
                minSdk = 21
            }

            compileOptions {
                sourceCompatibility = JavaVersion.VERSION_17
                targetCompatibility = JavaVersion.VERSION_17
            }
        }

        tasks.withType<KotlinCompile>().configureEach {
            kotlinOptions.jvmTarget = "17"
        }
    }
}